<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"mixley.github.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="当我们编写了博客后，想将博客内容发送到微信公众平台时，会遇到一个新的阻碍：图片需要重新上传。 MD转成微信样式后有很多方式，之前我们提到的md.openwrite.cn，或者直接使用OpenWrite中编辑文章后显示的公众号预览功能都能基本满足要求，但是！复制的内容粘贴在微信后，无法解决图片无法加载的问题，功能实用性大打折扣。 理清思路失败的素材的处理图片不是微信的，会提示失败图片，我们需要通过">
<meta property="og:type" content="article">
<meta property="og:title" content="快速上传微信素材">
<meta property="og:url" content="https://mixley.github.io/2021/1P5AD68.html">
<meta property="og:site_name" content="mixley">
<meta property="og:description" content="当我们编写了博客后，想将博客内容发送到微信公众平台时，会遇到一个新的阻碍：图片需要重新上传。 MD转成微信样式后有很多方式，之前我们提到的md.openwrite.cn，或者直接使用OpenWrite中编辑文章后显示的公众号预览功能都能基本满足要求，但是！复制的内容粘贴在微信后，无法解决图片无法加载的问题，功能实用性大打折扣。 理清思路失败的素材的处理图片不是微信的，会提示失败图片，我们需要通过">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://mixley.stdcdn.com/2021/07/68bbd53c0ed7e3797596e738ad1c8be8.png">
<meta property="og:image" content="https://mixley.stdcdn.com/2021/07/752819242ad82d1fbeba89cc4c373144.png">
<meta property="og:image" content="https://mixley.stdcdn.com/2021/07/76e2576d1cca88aeaa6722fdbb5ca9ad.png">
<meta property="og:image" content="https://mixley.stdcdn.com/2021/07/a3c4c1f72933512e083a2404bd147a84.png">
<meta property="og:image" content="https://mixley.stdcdn.com/2021/07/5882273b259e21171750eacdc8a9d86f.gif">
<meta property="article:published_time" content="2021-07-10T13:12:40.000Z">
<meta property="article:modified_time" content="2021-07-12T12:30:59.341Z">
<meta property="article:author" content="mixley">
<meta property="article:tag" content="mixley">
<meta property="article:tag" content="java">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://mixley.stdcdn.com/2021/07/68bbd53c0ed7e3797596e738ad1c8be8.png">

<link rel="canonical" href="https://mixley.github.io/2021/1P5AD68.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>快速上传微信素材 | mixley</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?c36eb18366b436984557126f16796f30";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">mixley</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">求上者得中·求中者得下</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://mixley.github.io/2021/1P5AD68.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="mixley">
      <meta itemprop="description" content="全栈·架构设计·算法">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="mixley">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          快速上传微信素材
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-07-10 21:12:40" itemprop="dateCreated datePublished" datetime="2021-07-10T21:12:40+08:00">2021-07-10</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-07-12 20:30:59" itemprop="dateModified" datetime="2021-07-12T20:30:59+08:00">2021-07-12</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/tool/" itemprop="url" rel="index"><span itemprop="name">工具</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Changyan：</span>
    
    
      <a title="changyan" href="/2021/1P5AD68.html#SOHUCS" itemprop="discussionUrl">
        <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="2021/1P5AD68.html" itemprop="commentCount"></span>
      </a>
    
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p> 当我们编写了博客后，想将博客内容发送到微信公众平台时，会遇到一个新的阻碍：图片需要重新上传。</p>
<p>MD转成微信样式后有很多方式，之前我们提到的<a target="_blank" rel="noopener" href="https://md.openwrite.cn/">md.openwrite.cn</a>，或者直接使用OpenWrite中编辑文章后显示的<strong>公众号预览</strong>功能都能基本满足要求，但是！复制的内容粘贴在微信后，无法解决图片无法加载的问题，功能实用性大打折扣。</p>
<h2 id="理清思路"><a href="#理清思路" class="headerlink" title="理清思路"></a>理清思路</h2><h3 id="失败的素材的处理"><a href="#失败的素材的处理" class="headerlink" title="失败的素材的处理"></a>失败的素材的处理</h3><p>图片不是微信的，会提示失败图片，我们需要通过点击<strong>查看失败图片</strong>找到对应的图片，然后选中失败图片后，点击<strong>图片</strong>-&gt;<strong>本地上传</strong>再从本地选择图片上传，若提前存图片库的，可以从图片库中选择。</p>
<p><img src="https://mixley.stdcdn.com/2021/07/68bbd53c0ed7e3797596e738ad1c8be8.png" alt="失败图片显示"></p>
<h3 id="重复动作梳理"><a href="#重复动作梳理" class="headerlink" title="重复动作梳理"></a>重复动作梳理</h3><p>1、找到失败图片，选中失败图片</p>
<p>2、获取失败图片路径</p>
<p>3、点击图片-&gt;本地上传</p>
<p>4、找到对应失败图片的本地路径</p>
<p>5、点击确定</p>
<h3 id="需要处理的核心问题"><a href="#需要处理的核心问题" class="headerlink" title="需要处理的核心问题"></a>需要处理的核心问题</h3><p>1、通过失败图片路径找到本地路径</p>
<p>2、重复动作太多，需要简化操作</p>
<h2 id="解决问题"><a href="#解决问题" class="headerlink" title="解决问题"></a>解决问题</h2><h3 id="替换图片路径为本地路径"><a href="#替换图片路径为本地路径" class="headerlink" title="替换图片路径为本地路径"></a>替换图片路径为本地路径</h3><p>我们可以uTools的自动化助手，帮我们将图片下载，然后替换成本地的路径</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">let</span> path = ENTER.payload</span><br><span class="line"><span class="comment">//路径为https://mixley.stdcdn.com/ 替换为应用中路径</span></span><br><span class="line"><span class="keyword">let</span> url=<span class="string">&quot;https://mixley.stdcdn.com/&quot;</span>;</span><br><span class="line"><span class="keyword">let</span> dic=<span class="string">&quot;C:/Users/micke/OneDrive/应用/PoweredBy.Cloud/mixley.stdcdn.com/&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//图片下载保存路径</span></span><br><span class="line"><span class="keyword">let</span> imgdowndir=<span class="string">&quot;E:/mixley/Pictures/Saved Pictures/&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//定义获取UUID的方法</span></span><br><span class="line"><span class="keyword">let</span> getUUID=<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  <span class="comment">//UUID来自UUID插件中算法</span></span><br><span class="line">  <span class="keyword">const</span> uuid = <span class="string">&#x27;xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx&#x27;</span>.replace(<span class="regexp">/[xy]/g</span>, <span class="function"><span class="params">c</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">let</span> r = <span class="built_in">Math</span>.random() * <span class="number">16</span> | <span class="number">0</span></span><br><span class="line">    <span class="keyword">let</span> v = c === <span class="string">&#x27;x&#x27;</span> ? r : (r &amp; <span class="number">0x3</span> | <span class="number">0x8</span>)</span><br><span class="line">    <span class="keyword">return</span> v.toString(<span class="number">16</span>)</span><br><span class="line">  &#125;)</span><br><span class="line">  <span class="keyword">return</span> uuid;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//定义执行路径</span></span><br><span class="line"><span class="keyword">let</span> executePath=<span class="function"><span class="keyword">function</span>(<span class="params">path</span>)</span>&#123;</span><br><span class="line">  utools.copyText(path);</span><br><span class="line">  utools.simulateKeyboardTap(<span class="string">&#x27;v&#x27;</span>,utools.isMacOs() ? <span class="string">&#x27;command&#x27;</span> : <span class="string">&#x27;ctrl&#x27;</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">if</span>(path.indexOf(url)&gt;-<span class="number">1</span>)&#123;</span><br><span class="line">  path = path.replace(url,dic);</span><br><span class="line">  executePath(path);</span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line"><span class="comment">//下面为下载图片后替换本地路径</span></span><br><span class="line">path = imgdowndir+getUUID()+<span class="string">&#x27;.png&#x27;</span>;</span><br><span class="line"><span class="comment">//下载</span></span><br><span class="line">utools.ubrowser.goto(ENTER.payload)</span><br><span class="line">  .wait(<span class="number">500</span>)</span><br><span class="line">  <span class="comment">//将Img截图，保存为png</span></span><br><span class="line">  .screenshot(<span class="string">&quot;img&quot;</span>, path)</span><br><span class="line">  .run(&#123; <span class="attr">show</span>: <span class="literal">false</span> &#125;)</span><br><span class="line">  .then(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    executePath(path)</span><br><span class="line">  &#125;)</span><br><span class="line">  .catch(<span class="function"><span class="params">err</span> =&gt;</span> &#123; utools.showNotification(err.message) &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><img src="https://mixley.stdcdn.com/2021/07/752819242ad82d1fbeba89cc4c373144.png" alt="自动化设置"></p>
<p><strong>特别说明</strong></p>
<p>如果使用OD作为图床，再OD中找到应用文件夹，将它设置为始终在此设备保留，解决同步问题。</p>
<p><img src="https://mixley.stdcdn.com/2021/07/76e2576d1cca88aeaa6722fdbb5ca9ad.png" alt="设置始终在此设备上保留"></p>
<h3 id="解决重复步骤问题"><a href="#解决重复步骤问题" class="headerlink" title="解决重复步骤问题"></a>解决重复步骤问题</h3><p>先看下浏览器有哪些操作可以让我们后面进行使用。</p>
<h4 id="浏览器特定操作说明"><a href="#浏览器特定操作说明" class="headerlink" title="浏览器特定操作说明"></a>浏览器特定操作说明</h4><p>1、Ctrl+L可以进入到link栏，即浏览器的地址栏（大部分浏览器）。</p>
<p>2、输入<strong>javascript:指令</strong>可以执行对应页面对应的指令，如下指令在浏览器地址栏输入后可在当前页面显示时间戳(注意，**javascript:**无法可能粘贴到浏览器，可以先输入j，再复制粘贴后面的部分)</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line">javascript:(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;alert((<span class="keyword">new</span> <span class="built_in">Date</span>()).valueOf());&#125;)();</span><br></pre></td></tr></table></figure>

<p>3、选择文件的文件框选择中，如果输入互联网地址，系统会自动下载文件，并且跳转到对应的本地路径，但是可能存在下载多次。</p>
<p><img src="https://mixley.stdcdn.com/2021/07/a3c4c1f72933512e083a2404bd147a84.png" alt="选择文件"></p>
<h4 id="微信公众号特定DOM元素及操作分析"><a href="#微信公众号特定DOM元素及操作分析" class="headerlink" title="微信公众号特定DOM元素及操作分析"></a>微信公众号特定DOM元素及操作分析</h4><p>咱们不用分析太多微信的内部逻辑，就顺着微信公众号的操作来简化，咱们是为了简化操作不是为了破解。</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">//获取到ueditor_0编辑器的上下文(iframe)</span></span><br><span class="line"><span class="built_in">document</span>.getElementById(<span class="string">&quot;ueditor_0&quot;</span>)</span><br><span class="line"><span class="comment">//下面为具体获取的document</span></span><br><span class="line"><span class="built_in">document</span>.getElementById(<span class="string">&quot;ueditor_0&quot;</span>).contentWindow.document</span><br><span class="line"><span class="comment">//说明，后面的document都是指上面这个方式获取的。</span></span><br></pre></td></tr></table></figure>

<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="comment">&lt;!--这个是获取到的错误图片的大概结构，具体内容分析见下--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">section</span> <span class="attr">class</span>=<span class="string">&quot;page_image_error js_catchremoteimageerror js_uneditable custom_select_card js_uneditablemouseover custom_select_card_selected&quot;</span> <span class="attr">data-remoteid</span>=<span class="string">&quot;c1625917818338&quot;</span> <span class="attr">data-scene</span>=<span class="string">&quot;catch&quot;</span> <span class="attr">data-global</span>=<span class="string">&quot;0&quot;</span> <span class="attr">data-canretry</span>=<span class="string">&quot;1&quot;</span> <span class="attr">data-reason</span>=<span class="string">&quot;%E6%8B%89%E5%8F%96%E5%9B%BE%E7%89%87%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5&quot;</span> <span class="attr">data-imgtype</span>=<span class="string">&quot;img&quot;</span> <span class="attr">data-cacheurl</span>=<span class="string">&quot;https://mixley.stdcdn.com/2021/07/maven/clip_image010.jpg&quot;</span> <span class="attr">data-filename</span>=<span class="string">&quot;undefined&quot;</span> <span class="attr">style</span>=<span class="string">&quot;width:553px;height:153px;&quot;</span> <span class="attr">contenteditable</span>=<span class="string">&quot;false&quot;</span>&gt;</span><span class="comment">&lt;!--省略--&gt;</span><span class="tag">&lt;/<span class="name">section</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>1、 选中到错误的图片</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">//获取方式1 可能存在多个，可以轮询。</span></span><br><span class="line"><span class="built_in">document</span>.getElementsByClassName(<span class="string">&quot;page_image_error&quot;</span>)[<span class="number">0</span>].click();</span><br><span class="line"><span class="comment">//获取选中图片</span></span><br><span class="line"><span class="built_in">document</span>.getElementsByClassName(<span class="string">&quot;page_image_error&quot;</span>)[<span class="number">0</span>];</span><br><span class="line"></span><br><span class="line"><span class="comment">//获取方式2 .js_msg_next 进行点击，模拟界面上 查看失败图片按钮，不建议</span></span><br><span class="line"><span class="built_in">document</span>.getElementsByClassName(<span class="string">&quot;js_msg_next&quot;</span>)[<span class="number">0</span>].click();</span><br><span class="line"><span class="comment">//获取选中图片</span></span><br><span class="line"><span class="built_in">document</span>.getElementsByClassName(<span class="string">&quot;custom_select_card_selected&quot;</span>)[<span class="number">0</span>];</span><br></pre></td></tr></table></figure>
<p>2、获取到错误图片的地址</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">//读取元素中的data-cacheurl,直接使用dataset</span></span><br><span class="line"><span class="built_in">document</span>.getElementsByClassName(<span class="string">&quot;page_image_error&quot;</span>)[<span class="number">0</span>].dataset.cacheurl</span><br></pre></td></tr></table></figure>

<p>3、点击上传按钮</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">//实际研究源码，是使用的jq，有兴趣的可以把图片下载后转base64，直接免打开上传按钮</span></span><br><span class="line"><span class="built_in">document</span>.getElementsByName(<span class="string">&quot;file&quot;</span>)[<span class="number">0</span>].click()</span><br></pre></td></tr></table></figure>

<p>4、粘贴并转换地址，这里使用替换图片路径为本地路径或者直接复制原地址</p>
<p>5、确定后上传，其余的步骤重复</p>
<h3 id="完整代码"><a href="#完整代码" class="headerlink" title="完整代码"></a>完整代码</h3><p>在uTools自动化工具中，我们编写代码</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">//定义替换图片的本地路径</span></span><br><span class="line"><span class="keyword">let</span> url=<span class="string">&quot;https://mixley.stdcdn.com/&quot;</span>;</span><br><span class="line"><span class="keyword">let</span> dic=<span class="string">&quot;C:/Users/micke/OneDrive/应用/PoweredBy.Cloud/mixley.stdcdn.com/&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//貌似会出现命令串行，需要暂停下</span></span><br><span class="line"><span class="keyword">let</span> sleep =<span class="function"><span class="keyword">function</span>(<span class="params">numberMillis</span>) </span>&#123; </span><br><span class="line">  <span class="keyword">let</span> now = <span class="keyword">new</span> <span class="built_in">Date</span>(); </span><br><span class="line">  <span class="keyword">let</span> exitTime = now.getTime() + numberMillis; </span><br><span class="line">  <span class="keyword">while</span> (<span class="literal">true</span>) &#123; </span><br><span class="line">    now = <span class="keyword">new</span> <span class="built_in">Date</span>(); </span><br><span class="line">    <span class="keyword">if</span> (now.getTime() &gt; exitTime) </span><br><span class="line">    <span class="keyword">return</span>; </span><br><span class="line">  &#125; </span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//此方法在浏览器中执行js语句，可以直接操作dom</span></span><br><span class="line"><span class="keyword">let</span> executeJs=<span class="function"><span class="keyword">function</span>(<span class="params">data</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">let</span> d = <span class="string">&#x27;let url=&quot;&#x27;</span>+url+<span class="string">&#x27;&quot;;&#x27;</span>+</span><br><span class="line">  <span class="string">&#x27;let dic=&quot;&#x27;</span>+dic+<span class="string">&#x27;&quot;;&#x27;</span>;</span><br><span class="line">  <span class="comment">//进入到浏览器地址栏</span></span><br><span class="line">  utools.simulateKeyboardTap(<span class="string">&#x27;l&#x27;</span>,utools.isMacOs() ? <span class="string">&#x27;command&#x27;</span> : <span class="string">&#x27;ctrl&#x27;</span>);</span><br><span class="line">  <span class="comment">//这里不停下，可能会将文本复制到正文</span></span><br><span class="line">  sleep(<span class="number">100</span>);</span><br><span class="line">  <span class="comment">//本来是先输入j再输入后面的内容的，但是发现中文输入有问题，改为录入后删除</span></span><br><span class="line">  <span class="keyword">let</span> val=<span class="string">&quot;_javascript:(function()&#123;&quot;</span>+d+data+<span class="string">&quot;&#125;)();&quot;</span></span><br><span class="line">  utools.copyText(val);</span><br><span class="line">  utools.simulateKeyboardTap(<span class="string">&#x27;v&#x27;</span>,utools.isMacOs() ? <span class="string">&#x27;command&#x27;</span> : <span class="string">&#x27;ctrl&#x27;</span>);</span><br><span class="line">  sleep(<span class="number">20</span>);</span><br><span class="line">  utools.simulateKeyboardTap(<span class="string">&#x27;home&#x27;</span>,utools.isMacOs() ? <span class="string">&#x27;command&#x27;</span> : <span class="string">&#x27;ctrl&#x27;</span>);</span><br><span class="line">  sleep(<span class="number">20</span>);</span><br><span class="line">  utools.simulateKeyboardTap(<span class="string">&#x27;delete&#x27;</span>);</span><br><span class="line">  sleep(<span class="number">20</span>);</span><br><span class="line">  utools.simulateKeyboardTap(<span class="string">&#x27;enter&#x27;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//注意，execCommand已废弃，替代方法暂无。</span></span><br><span class="line"><span class="comment">//执行的内容，获取图片地址，注意，结尾需要分号; 别写//注释哦，否则无法执行</span></span><br><span class="line"><span class="keyword">let</span> urlPath=<span class="string">`</span></span><br><span class="line"><span class="string">let editDocument = document.getElementById(&quot;ueditor_0&quot;).contentWindow.document;</span></span><br><span class="line"><span class="string">let errorimg = editDocument.getElementsByClassName(&quot;page_image_error&quot;);</span></span><br><span class="line"><span class="string">/**将文本复制到剪贴板，后期浏览器废弃后，升级为其它方式**/</span></span><br><span class="line"><span class="string">let copyText=function(text)&#123;</span></span><br><span class="line"><span class="string">  let input = document.createElement(&#x27;input&#x27;);</span></span><br><span class="line"><span class="string">  input.setAttribute(&quot;value&quot;, text);</span></span><br><span class="line"><span class="string">  document.body.appendChild(input);</span></span><br><span class="line"><span class="string">  input.select();</span></span><br><span class="line"><span class="string">  document.execCommand(&quot;copy&quot;); </span></span><br><span class="line"><span class="string">  document.body.removeChild(input);</span></span><br><span class="line"><span class="string">&#125;;</span></span><br><span class="line"><span class="string">if(errorimg.length)&#123;</span></span><br><span class="line"><span class="string">  errorimg[0].click();</span></span><br><span class="line"><span class="string">  let cacheurl = errorimg[0].dataset.cacheurl;</span></span><br><span class="line"><span class="string">  /**替换为本地路径**/</span></span><br><span class="line"><span class="string">  cacheurl = cacheurl.replace(url,dic);</span></span><br><span class="line"><span class="string">  if(cacheurl.indexOf(dic)&gt;-1)&#123;</span></span><br><span class="line"><span class="string">    cacheurl=cacheurl.replaceAll(&quot;/&quot;, &quot;\\\\&quot;);</span></span><br><span class="line"><span class="string">  &#125;;</span></span><br><span class="line"><span class="string">  copyText(cacheurl);</span></span><br><span class="line"><span class="string">  /**此处使用模拟打开文件上传的方式，可以替换为其它，源码是操作base64的，我懒得解析了，够用**/</span></span><br><span class="line"><span class="string">  document.getElementsByName(&quot;file&quot;)[0].click();</span></span><br><span class="line"><span class="string">&#125;;</span></span><br><span class="line"><span class="string">`</span></span><br><span class="line"><span class="comment">//开始执行(可以写循环，全部执行完毕，判断条件)</span></span><br><span class="line">executeJs(urlPath);</span><br><span class="line"><span class="comment">//依据电脑性能停留不同的时间</span></span><br><span class="line">sleep(<span class="number">500</span>);</span><br><span class="line">utools.simulateKeyboardTap(<span class="string">&#x27;v&#x27;</span>,utools.isMacOs() ? <span class="string">&#x27;command&#x27;</span> : <span class="string">&#x27;ctrl&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//这里回车可以你自己按下去,继续使用前面提供的替换脚本，将图片快速下载，使用自带的下载比较慢</span></span><br><span class="line"><span class="comment">// sleep(20);</span></span><br><span class="line"><span class="comment">// utools.simulateKeyboardTap(&#x27;enter&#x27;);</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="演示效果"><a href="#演示效果" class="headerlink" title="演示效果"></a>演示效果</h2><p><img src="https://mixley.stdcdn.com/2021/07/5882273b259e21171750eacdc8a9d86f.gif" alt="动画3"></p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/mixley/" rel="tag"># mixley</a>
              <a href="/tags/java/" rel="tag"># java</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/1DC25F7.html" rel="prev" title="图片的由来与存储">
      <i class="fa fa-chevron-left"></i> 图片的由来与存储
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/16VX7F1.html" rel="next" title="vscodium使用vscode扩展">
      vscodium使用vscode扩展 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    
  <div class="comments">
    <div id="SOHUCS"></div>
  </div>
  

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%90%86%E6%B8%85%E6%80%9D%E8%B7%AF"><span class="nav-number">1.</span> <span class="nav-text">理清思路</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%A4%B1%E8%B4%A5%E7%9A%84%E7%B4%A0%E6%9D%90%E7%9A%84%E5%A4%84%E7%90%86"><span class="nav-number">1.1.</span> <span class="nav-text">失败的素材的处理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%87%8D%E5%A4%8D%E5%8A%A8%E4%BD%9C%E6%A2%B3%E7%90%86"><span class="nav-number">1.2.</span> <span class="nav-text">重复动作梳理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9C%80%E8%A6%81%E5%A4%84%E7%90%86%E7%9A%84%E6%A0%B8%E5%BF%83%E9%97%AE%E9%A2%98"><span class="nav-number">1.3.</span> <span class="nav-text">需要处理的核心问题</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E9%97%AE%E9%A2%98"><span class="nav-number">2.</span> <span class="nav-text">解决问题</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9B%BF%E6%8D%A2%E5%9B%BE%E7%89%87%E8%B7%AF%E5%BE%84%E4%B8%BA%E6%9C%AC%E5%9C%B0%E8%B7%AF%E5%BE%84"><span class="nav-number">2.1.</span> <span class="nav-text">替换图片路径为本地路径</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E9%87%8D%E5%A4%8D%E6%AD%A5%E9%AA%A4%E9%97%AE%E9%A2%98"><span class="nav-number">2.2.</span> <span class="nav-text">解决重复步骤问题</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%B5%8F%E8%A7%88%E5%99%A8%E7%89%B9%E5%AE%9A%E6%93%8D%E4%BD%9C%E8%AF%B4%E6%98%8E"><span class="nav-number">2.2.1.</span> <span class="nav-text">浏览器特定操作说明</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E5%8F%B7%E7%89%B9%E5%AE%9ADOM%E5%85%83%E7%B4%A0%E5%8F%8A%E6%93%8D%E4%BD%9C%E5%88%86%E6%9E%90"><span class="nav-number">2.2.2.</span> <span class="nav-text">微信公众号特定DOM元素及操作分析</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81"><span class="nav-number">2.3.</span> <span class="nav-text">完整代码</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%BC%94%E7%A4%BA%E6%95%88%E6%9E%9C"><span class="nav-number">3.</span> <span class="nav-text">演示效果</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">mixley</p>
  <div class="site-description" itemprop="description">全栈·架构设计·算法</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">43</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">mixley</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

  <script>
  NexT.utils.loadComments(document.querySelector('#SOHUCS'), () => {
    var appid = 'cyvxnSprz';
    var conf = 'prod_45d8f2d8bd5b14b5c44442e45f977f85';
    var width = window.innerWidth || document.documentElement.clientWidth;
    if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>');
    } else {
      var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})});
    }
  });
  </script>
  <script src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>

</body>
</html>
